package com.macro.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsLabelParam;
import com.macro.mall.model.BmsLabel;
import com.macro.mall.service.BmsLabelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Controller
@Api(tags = "BmsLabel")
@Tag(name = "BmsLabel", description = "标签")
@RequestMapping("/bmsLabel")
public class BmsLabelController {

    @Autowired
    private BmsLabelService bmsLabelService;
    
    @ApiOperation("添加标签")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsLabelParam bmsLabelParam) {
        int count = bmsLabelService.create(bmsLabelParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("修改标签")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsLabelParam bmsLabelParam) {
        int count = bmsLabelService.update(bmsLabelParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("分页标签")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsLabel>> getList(@RequestBody BmsLabelParam bmsLabelParam) {
        List<BmsLabel> bmsLabel = bmsLabelService.getList(bmsLabelParam);
        return CommonResult.success(CommonPage.restPage(bmsLabel));
    }
    
    @ApiOperation("根据id获取标签")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsLabel> getItem(@PathVariable Long id) {
        BmsLabel bmsLabel = bmsLabelService.getItem(id);
        return CommonResult.success(bmsLabel);
    }
    
    @ApiOperation("删除标签")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsLabelService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
